<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let str = `#`,flag
        let arr = ['1','2','3','4','5','6','7','8','a','b','c','d','e','f']
        function getRandomColor(flag){
            if(flag){
                for(let i = 0;i < 6;i++){
                    let hex = Math.floor(Math.random()*arr.length)
                    str += arr[hex]
                    // return  `#${hex}`
                }
                return str
            }
            else{
                let colorOne = Math.floor(Math.random()*256)
                let colorTwo = Math.floor(Math.random()*256)
                let colorThree = Math.floor(Math.random()*256)
                return `rgb(${colorOne},${colorTwo},${colorThree})`
            }
        }
       console.log(getRandomColor(true))
       console.log(getRandomColor(flag))
    </script>
</body>
</html>